package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;

import sjtu.ist.warehouse4ws.model.Functionpoint;
import sjtu.ist.warehouse4ws.model.Parameter;
import sjtu.ist.warehouse4ws.service.FunctionpointService;
import sjtu.ist.warehouse4ws.service.ParameterService;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowFunctionAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1630812068619442991L;
	private List<Parameter> parameterList=new ArrayList<Parameter> ();
	private ParameterService parameterService;
	private FunctionpointService functionPointService; 
	private List<Functionpoint> functionpointList=new ArrayList<Functionpoint> ();
	private String functionId;
	
	
	public String getFunctionId() {
		return functionId;
	}

	public void setFunctionId(String functionId) {
		this.functionId = functionId;
	}

	public void setParameterService(ParameterService parameterService) {
		this.parameterService = parameterService;
	}
	
	public void setFunctionpointService(FunctionpointService functionPointService) {
		this.functionPointService = functionPointService;
	}

	public String showFunctionPoint()
	{
		HttpServletRequest request = ServletActionContext.getRequest ();
		this.functionId=request.getParameter("cid");
		this.functionpointList = functionPointService.getFunctionPoint(functionId);
		
		//插入日志记录/////////////////////////////////////////////////////
//		Functionpoint fp=functionPointService.getFunctionPoint(functionId);
//		ActionContext actionContext = ActionContext.getContext();
//		Map session = actionContext.getSession();
//		String user_id = session.get("user_id").toString();
	//	oplogService.recordLog(user_id, fp.getFileId(), "查看功能模型", "readop");
		//////////////////////////////////////////////////////////////////////
		
		return SUCCESS;
		
	}
    

	@JSON(name = "totalFunctionpoint")
	public int getTotalFunctionpoint() {
		return this.functionpointList.size();
	}


	@JSON(name ="functionpoint")	
	public List<Functionpoint> getFunctionpoint() {
		return this.functionpointList;
	}

	public String showParameter()
	{
		HttpServletRequest request = ServletActionContext.getRequest ();
		this.functionId=request.getParameter("cid");
		this.parameterList=parameterService.getParameterList(functionId);
		
		//插入日志记录/////////////////////////////////////////////////////
//		Functionpoint fp=functionPointService.getFunctionPoint(functionId);
//		ActionContext actionContext = ActionContext.getContext();
//		Map session = actionContext.getSession();
//		String user_id = session.get("user_id").toString();
	//	oplogService.recordLog(user_id, fp.getFileId(), "查看功能模型", "readop");
		//////////////////////////////////////////////////////////////////////
		
		return SUCCESS;
		
	}
	@JSON(name = "totalParameter")	
	public int getTotalParameter() {
		return this.parameterList.size();
	}
    
	@JSON(name ="parameter")	
	public List<Parameter> getParameterList() {
		return this.parameterList;
	}
	
}
